using System;
using UnityEngine;

public class Ads
{
	private static Ads _instance;

	private ConfigBase config;

	protected bool interstitialCreated;

	protected bool interstitialLoading;

	public static Ads instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = new Ads();
			}
			return _instance;
		}
	}

	public bool isPromotedUser
	{
		get
		{
			GGPlayerSettings gGPlayerSettings = GGPlayerSettings.instance;
			DateTime creationTime = new DateTime(gGPlayerSettings.Model.creationTime);
			return GetIsPromotedUser(creationTime);
		}
	}

	public bool shouldShowAds
	{
		get
		{
			if (isPromotedUser)
			{
				Debug.Log("Promoted user, don't show ads");
				return false;
			}
			if (PlayerInventory.instance.isOwned(PlayerInventory.Item.NoAds))
			{
				return false;
			}
			return !config.isProVersionEnabled;
		}
	}

	protected string interstitialAdId
	{
		get
		{
			if (!string.IsNullOrEmpty(ConfigBase.instance.interstitialAdId))
			{
				return ConfigBase.instance.interstitialAdId;
			}
			return string.Empty;
		}
	}

	public bool adsShown { get; private set; }

	private Ads()
	{
		config = ConfigBase.instance;
	}

	public bool GetIsPromotedUser(DateTime creationTime)
	{
		if (!config.noAdsOnPromotionDay)
		{
			return false;
		}
		DateTime result;
		if (!DateTime.TryParse(config.promotionStart, out result))
		{
			return false;
		}
		DateTime result2;
		if (!DateTime.TryParse(config.promotionEnd, out result2))
		{
			return false;
		}
		Debug.Log(string.Concat("start ", result, " end ", result2));
		Debug.Log("Creation time " + creationTime);
		bool flag = creationTime > result && creationTime < result2;
		Debug.Log("Is promote " + flag);
		return flag;
	}

	public void CreateInterstitial()
	{
		if (shouldShowAds && !interstitialCreated)
		{
			GGMoPub.instance.createInterstitial(interstitialAdId);
			interstitialCreated = true;
		}
	}

	public void LoadInterstitial()
	{
		if (shouldShowAds)
		{
			if (ConfigBase.instance.shouldShowAmazonAds)
			{
				Singleton<GGAmazonAds>.Instance.loadInterstitial(ConfigBase.instance.amazonAppKey);
			}
			GGMoPub.instance.load();
		}
	}

	public bool isInterstitialReady()
	{
		return GGMoPub.instance.isReady() || (ConfigBase.instance.shouldShowAmazonAds && Singleton<GGAmazonAds>.Instance.isReady());
	}

	public void ShowInterstitial()
	{
		if (!shouldShowAds)
		{
			return;
		}
		if (isInterstitialReady())
		{
			if (ConfigBase.instance.shouldShowAmazonAds && Singleton<GGAmazonAds>.Instance.isReady())
			{
				Singleton<GGAmazonAds>.Instance.showInterstitial();
			}
			else
			{
				GGMoPub.instance.show();
			}
		}
		else
		{
			LoadInterstitial();
		}
	}

	public void createBanner()
	{
		if (shouldShowAds)
		{
			adsShown = true;
		}
	}

	public void hideBanner(bool hideBanner)
	{
		if (adsShown && !shouldShowAds)
		{
			hideBanner = true;
		}
	}
}
